<template>
  <div @touchstart="touchstart" @touchmove="touchmove">
    <van-popup
      class="popup"
      v-model="show"
      position="bottom"
      :style="{ height: '30%', width: '100%' }"
    >
      <van-form @submit="onSubmit">
        <van-field name="radio" label="是否试用成功">
          <template #input>
            <van-radio-group
              v-model="entity.SampleStatus"
              direction="horizontal"
            >
              <van-radio name="1">是</van-radio>
              <van-radio name="2">否</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field
          v-model="entity.SampleTrialRemark"
          label="说明"
          placeholder="说明"
        />
        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit"
            >提交</van-button
          >
        </div>
      </van-form>
      <!-- <div class="confirmBtn">
        <van-button
          size="mini"
          class="comBtn"
          @click="show = false"
          type="danger"
          >取消</van-button
        >
        <van-button size="mini" class="comBtn" @click="confrim" type="info"
          >确认</van-button
        >
      </div> -->
      <!-- <van-cell title="是否试用成功">
        <template #right-icon>
          <van-switch v-model="checked" size="24" />
        </template>
      </van-cell> -->
    </van-popup>
  </div>
</template>

<script>
import { Toast } from "vant";
export default {
  props: {
    parentObj: Object
  },
  data() {
    return {
      id: "",
      show: false,
      checked: true,
      entity: {},
      radio: 2
    };
  },
  methods: {
    swipeleft() {
      this.show = false;
      // alert("123");
    },
    touchstart(e) {
      // alert("123");

      // e.preventDefault();

      this.startX = e.touches[0].clientX;
      this.startY = e.touches[0].clientY;
    },
    touchmove(e) {
      //    this.show = false;
      // e.preventDefault();
      this.moveX = e.touches[0].clientX;
      this.moveY = e.touches[0].clientY;
      // this.startX - this.moveX <= 0
      //   ? console.log("你在往右滑")
      //   : console.log("你在往左滑");
    },

    onSubmit() {
      let searchArr = [];
      if (this.entity.SampleTrialRemark) {
        searchArr = [
          {
            Condition: "SampleTrialRemark",
            Keyword: this.entity.SampleTrialRemark
          },
          {
            Condition: "SampleStatus",
            Keyword: this.entity.SampleStatus
          }
        ];
      } else {
        searchArr = [
          {
            Condition: "SampleStatus",
            Keyword: this.entity.SampleStatus
          }
        ];
      }

      this.http
        .post("/SampleManagement/SPL_SampleApplyMain/UpdateDataByCondition", {
          Conditions: searchArr,
          ids: [this.id]
        })
        .then(resJson => {
          if (resJson.Success) {
            Toast.success("操作成功!");
            this.show = false;

            this.parentObj.getDataList();
          } else {
            Toast.fail(resJson.Msg);
          }
        });
    },
    openForm(Id) {
      this.show = true;
      this.entity = {};
      this.$set(this.entity, "SampleStatus", "1");
      this.id = Id;
    },
    confrim() {}
  }
};
</script>

<style scoped>
.popup {
  border-radius: 20px 20px 0 0;
}
.content {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
  overflow: hidden;
}
.confirmBtn {
  position: fixed;
  top: 50%;
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 0 10px;
  line-height: 2;
  background-color: #fff;
  box-sizing: border-box;
  z-index: 100;
  border-radius: 20px 20px 0 0;
}
.comBtn {
  border-radius: 4px;
  margin-top: 5px;
}
</style>
